#include "includes.h"


#define MQTT_MODBUS_CONFIG_MAX  3000
#define MQTT_MODBUS_READ_MAX    1000
#define MQTT_MODBUS_WRITE_MAX   50
#define MODBUS_READ_1X_MAX      800
#define MODBUS_READ_2X_MAX      800
#define MODBUS_READ_3X_MAX      100
#define MODBUS_READ_4X_MAX      100

typedef struct mqtt_modbus_config_t{
    union{
        unsigned int v;
        struct {
            unsigned int change:1;
            unsigned int greater:1;
            unsigned int equal:1;
            unsigned int less:1;
        }s;
    }flag;
    uint8_t  sent;
    uint8_t  used;
    uint8_t  dev_addr;
    uint8_t  reg_type;
    uint16_t reg_addr;
    uint16_t reg_value;
    uint16_t reg_value_old;
    uint16_t tigger_greater;
    uint16_t tigger_equal;
    uint16_t tigger_less;
}mqtt_modbus_config_t;

typedef struct mqtt_modbus_read_cmd_t{
    uint8_t  dev_addr;
    uint8_t  reg_type;
    uint16_t reg_addr;
    uint16_t reg_num;
}mqtt_modbus_read_cmd_t;

typedef struct mqtt_modbus_write_cmd_t{
    uint8_t  type;
    uint16_t addr;
    uint16_t data;
}mqtt_modbus_write_cmd_t;

extern mqtt_modbus_read_cmd_t mqtt_modbus_read_cmd[MQTT_MODBUS_READ_MAX];
extern mqtt_modbus_write_cmd_t mqtt_modbus_write_cmd[MQTT_MODBUS_WRITE_MAX];
extern mqtt_modbus_config_t mqtt_modbus_config[MQTT_MODBUS_CONFIG_MAX];

int mqtt_modbus_config_add(uint8_t  dev_addr, uint8_t  reg_type, uint16_t reg_addr, uint16_t flag, uint16_t tigger_greater, uint16_t tigger_equal, uint16_t tigger_less);
int mqtt_modbus_config_delete(uint8_t  dev_addr, uint8_t  reg_type, uint16_t reg_addr);
int mqtt_modbus_config_update(uint8_t  dev_addr, uint8_t  reg_type, uint16_t reg_addr, uint16_t reg_value);
int mqtt_modbus_config_get_index(uint8_t  dev_addr, uint8_t  reg_type, uint16_t reg_addr);
int mqtt_modbus_config_print(uint8_t  dev_addr, uint8_t  reg_type, uint16_t reg_addr);
int mqtt_genarate_modbus_cmds(void);
int mqtt_modbus_read_config_file(void);
